package data;

import java.io.File;

import sagex.api.Configuration;

public class ShowData
{
    private String _title;
    private String _showId;
    private String _fileName;
    private String _newFileName = "";
    private String _date;
    private Boolean _hasCompressFile = null;
    private boolean _isInSelectedView = false;
    
    public boolean isNewNameInSageDirs()
    {
        String newFileName = getNewFileName();
        if ( newFileName== null || newFileName.isEmpty())
            return true;
        
        if (newFileName.indexOf("\\") == -1
                && newFileName.indexOf("/") == -1)
        {
            return true;
        }
        
        File newFile = new File(getNewFileName());
//        if (newFile == null)
//            return false;
        
        File[] dirs = Configuration.GetVideoDirectories();
        for (int i = 0; i < dirs.length; i++)
        {
            File directory = dirs[i];
            if (newFile.getAbsolutePath().equals(directory.getAbsolutePath()))
            {
                return true;
            }
        }

        return false;
    }

    public boolean isInSelectedView()
    {
        return _isInSelectedView;
    }

    public void setInSelectedView(boolean isInSelectedView)
    {
        _isInSelectedView = isInSelectedView;
    }

    public Boolean getHasCompressFile(boolean force)
    {
        if (_hasCompressFile == null || force)
        {
            File f = new File(_fileName);
            if (!f.exists())
                _hasCompressFile = false;
            
            String s = _fileName.substring(0, _fileName.lastIndexOf(".")+1) + "compress";
            f = new File(s);
            if (!f.exists())
                _hasCompressFile = false;
            else
                _hasCompressFile = true;
        }
        return _hasCompressFile;
    }

    public Boolean getHasProjectFile(boolean force)
    {
        if (_hasProjectFile == null || force)
        {
            File f = new File(_fileName);
            if (!f.exists())
                _hasProjectFile = false;
            
            String s = _fileName.substring(0, _fileName.lastIndexOf(".")+1) + "project";
            f = new File(s);
            if (!f.exists())
                _hasProjectFile = false;
            else
                _hasProjectFile = true;
        }
        return _hasProjectFile;
    }

    public void setHasProjectFile(Boolean hasProjectFile)
    {
        _hasProjectFile = hasProjectFile;
    }

    private Boolean _hasProjectFile = null;
    
    public String getDate()
    {
        return _date;
    }

    public void setDate(String date)
    {
        _date = date;
    }

    public ShowData()
    {
    }

    public ShowData(String _title, String id, String name)
    {
        super();
        this._title = _title;
        _showId = id;
        _fileName = name;
    }

    public String getTitle()
    {
        return _title;
    }

    public void setTitle(String title)
    {
        _title = title;
    }

    public String getShowId()
    {
        return _showId;
    }

    public void setShowId(String showId)
    {
        _showId = showId;
    }

    public String getFileName()
    {
        return _fileName;
    }

    public void setFileName(String fileName)
    {
        _fileName = fileName;
    }

    public String getNewFileName()
    {
        return _newFileName;
    }

    public void setNewFileName(String newFileName)
    {
        _newFileName = newFileName;
    }
    
    public void refreshState()
    {
        getHasCompressFile(true);
        getHasProjectFile(true);
    }
    
    @Override
    public boolean equals(Object obj)
    {
        if (!(obj instanceof ShowData))
            return false;
        
        return getShowId().equals(((ShowData)obj).getShowId());
    }
}